//
//  ViewController.m
//  按钮交互_button
//
//  Created by mir_yan on 2018/10/2.
//  Copyright © 2018年 hakeem. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (strong, nonatomic) IBOutlet UIControl* myControl;

// 输出口
- (IBAction)ACTION:(id)sender;
- (IBAction)buttonAction:(id)sender;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIControl* control = [[UIControl alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    control.backgroundColor = [UIColor redColor];
    
    [self.view addSubview:control];
    
    control.tag = 11;
    
    //Target 必须能响应action
    [control addTarget:self action:@selector(touchAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.myControl setBackgroundColor:[UIColor greenColor]];
}

- (NSInteger)randomColorValue {
    return random()%255 + 1;
}

// 背景颜色随机变化
- (void)touchAction:(id)sender {
//    UIColor* randColor = [UIColor colorWithRed:[self randomColorValue]/255.0 green:[self randomColorValue]/255.0 blue:[self randomColorValue]/255.0 alpha:1];
//    [self.view setBackgroundColor:randColor];
    
    // sender是一个指针  总是指向识别用户事件的那个控件
    // self 通常是关联对象
    
    UIView* senderView = (UIView*)sender;
    NSLog(@"touch action tag:%ld", senderView.tag);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)ACTION:(id)sender {
}

- (IBAction)buttonAction:(id)sender {
}
@end
